package com.cooper.resource.download;

import java.util.Comparator;

public class DownloadComparator implements Comparator<DownloadStatus> {

	public static DownloadComparator instance;

	public static DownloadComparator getInstance() {
		if (instance == null) {
			instance = new DownloadComparator();
		}
		return instance;
	}

	private DownloadComparator() {
		super();
	}

	@Override
	public int compare(DownloadStatus object1, DownloadStatus object2) {
		if (object1.getDownloadResource().isFinish()
				&& !object2.getDownloadResource().isFinish()) {
			return -1;
		} else if (!object1.getDownloadResource().isFinish()
				&& object2.getDownloadResource().isFinish()) {
			return 1;
		} else {
			return object1.getDownloadResource().getAddTime()
					.compareTo(object2.getDownloadResource().getAddTime());
		}
	}

}
